define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'matketing/sale_rank/index' + location.search,
                    index_url2: 'matketing/sale_rank/index2' + location.search,
                    add_url: 'matketing/sale_rank/add',
                    edit_url: 'matketing/sale_rank/edit',
                    del_url: 'matketing/sale_rank/del',
                    multi_url: 'matketing/sale_rank/multi',
                    import_url: 'matketing/sale_rank/import',
                    table: 'sale_rank',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        // {checkbox: true},
                        {field: 'id', title: __('Id'),operate:false},
                        // {field: 'type', title: __('Type'), searchList: {"10":__('Type 10'),"20":__('Type 20')}, formatter: Table.api.formatter.normal},
                        {field: 'rank', title: __('Rank'),operate:false},
                        {field: 'price', title: __('Price'), operate:false},
                        {field: 'count', title: __('Count'),operate:false},
                        {field: 'discount', title: __('Discount'),operate:false},
                        {field: 'user_id', title: '销售',formatter:function(value,row,index){
                            return `<div>姓名:${row.user?.nickname}</div><div>手机号:${row.user?.mobile}</div>`
                        },searchList:$.getJSON('user/user/getSaleJson')},
                        {field: 'date', title: __('Date'), operate:false, addclass:'datetimerange', autocomplete:false,data: 'data-date-format="YYYY-MM-DD"'},
                        {field: 'createtime', title: __('Createtime'), operate:false, addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);


            var table2 = $("#table2");

            // 初始化表格
            table2.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url2,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        // {checkbox: true},
                        {field: 'id', title: __('Id'),operate:false},
                        // {field: 'type', title: __('Type'), searchList: {"10":__('Type 10'),"20":__('Type 20')}, formatter: Table.api.formatter.normal},
                        {field: 'rank', title: __('Rank'),operate:false},
                        {field: 'price', title: __('Price'), operate:false},
                        {field: 'count', title: __('Count'),operate:false},
                        {field: 'discount', title: __('Discount'),operate:false},
                        {field: 'user_id', title: '销售',formatter:function(value,row,index){
                            return `<div>姓名:${row.user?.nickname}</div><div>手机号:${row.user?.mobile}</div>`
                        },searchList:$.getJSON('user/user/getSaleJson')},
                        {field: 'date', title: __('Date'), operate:false, addclass:'datetimerange', autocomplete:false,data: 'data-date-format="YYYY-MM-DD"'},
                        {field: 'createtime', title: __('Createtime'), operate:false, addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table2);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
